<?php
namespace app\admin\controller;
use \think\Controller;
use \think\captcha\Captcha;
use \think\Db;
use \think\Session;
use app\admin\model\Login;
use app\admin\model\Logout;
class Index extends Controller
{
	public function index()
    {
    	if(input('?param.err')){
    		echo "<script>alert('请登录后访问');</script>";
    	}

    	if(request()->isPost()){
			//验证用户名密码
			$a=input('adminname');
			$p=input('password');
			
			// 实例化模型
			$log = new Login;
			//1 用户不存在 2 密码错误 3正确
			$result = $log->login($a,$p);
			if($result==1){
				echo "<script>alert('用户名不存在');</script>";
			}else if($result==2){
				echo "<script>alert('密码错误');</script>";
			}else{
				$this->redirect("user/index");
			}
		
   	 }
        return $this->fetch();
    }

    public function logout(){
    	$logout = new Logout;
    	$result = $logout->logout();
    	if($result==1){
    		$this->redirect("index/index");
    	}
    }

	
}